package org.kaka.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.kaka.dto.ChapterDto;
import org.kaka.mapper.ChapterMapper;
import org.kaka.mapper.ContentMapper;
import org.kaka.po.ChapterPo;
import org.kaka.utils.PageResponseData;
import org.kaka.vo.BookVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ChapterServiceImpl {
    @Autowired
    private ChapterMapper chapterMapper;
    @Autowired
    private ContentMapper contentMapper;

    public Object list(ChapterPo chapterDto) {
        Page<ChapterDto> result = PageHelper.startPage(chapterDto.getPageIndex(), chapterDto.getPageSize());
        List<ChapterDto> list = chapterMapper.list(chapterDto);
        PageResponseData<ChapterDto> pageResponseData= new PageResponseData<>(list,result.getTotal(),result.getPages());
        return pageResponseData;
    }

    public void delete(Long id) {
        chapterMapper.deleteById(id);
        contentMapper.deleteByChapterId(id);
    }
}
